package com.demo.handler;

import com.demo.controller.BaseController;
import com.demo.exception.SignException;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

/**
 * @Description 全局异常处理器
 * @Author Dang Xianyue
 * @Date 2020-08-09 15:45
 * @Version 1.0
 */
@RestControllerAdvice
public class GlobalExceptionHandler extends BaseController {

    @ExceptionHandler(Exception.class)
    public Object doHandleBindException(Exception e) {
        if (e instanceof SignException){
            return fail(((SignException) e).getCode(),((SignException) e).getMsg());
        }
        return fail(201,"服务器异常");
    }
}
